const express = require('express');
const http = require('http');
const cors = require('cors');
const authRoutes = require('./routes/authRoutes');
const userRoutes = require('./routes/userRoutes');
const friendRoutes = require('./routes/friendRoutes');
const chatRoutes = require('./routes/chatRoutes');
const activityCheck = require('./middlewares/activityCheck');
const setupWebSocket = require('./services/websocket');
const groupRoutes = require('./routes/groupRoutes');
const allGroupRoutes = require('./routes/allGroupRoutes');
const messageRoutes = require('./routes/messageRoutes');

const app = express();
const server = http.createServer(app);

app.use(cors());
app.use(express.json());
app.use(activityCheck);

app.use('/api/auth', authRoutes);
app.use('/api/users', userRoutes);
app.use('/api', friendRoutes);
app.use('/api/chat', chatRoutes);
app.use('/api/groups', groupRoutes);
app.use('/api/all-group', allGroupRoutes);
app.use('/api', messageRoutes);

setupWebSocket(server);

const PORT = process.env.PORT || 5000;
server.listen(PORT, () => {
  console.log(`Server running on port ${PORT}`);
  console.log(`WebSocket server started`);
}); 